package com.galleryviewpager.e_drawer_menu;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

public class TestDrawerMenuViewGroup extends ViewGroup {

    public TestDrawerMenuViewGroup(Context context) {
        this(context, null);
    }

    public TestDrawerMenuViewGroup(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public TestDrawerMenuViewGroup(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        for (int i = 0; i < getChildCount(); i++) {
            measureChild(getChildAt(i), widthMeasureSpec, heightMeasureSpec);
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {

        int currentX = 0, currentY = 0;

        for (int i = 0; i < getChildCount(); i++) {
            View childAt = getChildAt(i);
            currentX += childAt.getMeasuredWidth();
            currentY += childAt.getMeasuredHeight();
            childAt.layout(0, getMeasuredHeight() - currentY, childAt.getMeasuredWidth(), getMeasuredHeight() - currentY + childAt.getMeasuredHeight());
        }
//        layoutBottom();
    }

    private void layoutBottom() {
        Button button = (Button) getChildAt(0);
        button.layout(0, getMeasuredHeight() - button.getMeasuredHeight(), getMeasuredWidth(), getMeasuredHeight());
    }
}
